package liecai_class.day02;

/**
 * 递归
 */
public class Recursion {
    public static void main(String[] args) {
        System.out.println(plus(100));
        System.out.println(factorial(5));
    }

    /**
     * 该方法用于计算1+2+3+...+n
     */
    public static int plus(int n) {
        if (n == 1)
            return 1;
        int sum = n + plus(n - 1);
        return sum;
    }

    /**
     * 该方法用于计算n的阶乘
     */
    public static int factorial(int n) {
        if (n == 1)
            return 1;
        int multi = n * factorial(n - 1);
        return multi;
    }
}

